package offer;

import java.util.Arrays;
import java.util.PrimitiveIterator;

public class maopaopaixuan {
    public static void main(String[] args) {
        int[] array = {2,5,1,6,4,9,8,3,1,2,0};
        int[] bu = bubble(array);
/*        for (int i : bu) {
            System.out.println(i);
        }*/

        PrimitiveIterator.OfInt iterator = Arrays.stream(bu).iterator();

        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }

    private static int[] bubble(int[] array) {
        int temp = 0;
        for (int i = 0; i < array.length-1; i++) {
            int flag = 0;
            for (int j = 0; j < (array.length - 1 - i); j++) {
                if (array[j+1]>array[j]){
                    temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                    flag = 1;
                }
            }
            if (flag == 0)break;
        }
        return array;
    }


}
